---
id: rotate-in-out
title: Rotate In Out
sidebar_label: Rotate In Out
description: Rotate In Out animation
keywords:
  - custom-animations
  - rotate-in-out
  - carousel animation
  - carousel animation rotate-in-out
  - react-native-reanimated-carousel
  - reanimated-carousel
  - reanimated carousel
  - react-native
  - snap-carousel
  - react native
  - snap carousel
  - ios
  - android
  - carousel
  - snap
  - reanimated
image:
slug: /examples/custom-animations/rotate-in-out
---

{/* 

=========================================================================
=========================================================================
This page generated by /scripts/gen-pages.mjs, Don't update it manually 
=========================================================================
=========================================================================

*/}

import { Tabs } from 'nextra/components'
import { Callout } from 'nextra/components'
import Demo from '@/components/Demo'

<Callout type="info" emoji="💡">
  Check out the `rotate-in-out` animation demo for the full source code [here](https://github.com/dohooo/react-native-reanimated-carousel/blob/main/example/app/app/demos/custom-animations/rotate-in-out/index.tsx)
</Callout>

<Demo kind="custom-animations" name="rotate-in-out" />

```tsx copy
import * as React from "react";
import { View } from "react-native";
import { interpolate } from "react-native-reanimated";
import Carousel, { TAnimationStyle } from "react-native-reanimated-carousel";

import { SBItem } from "@/components/SBItem";
import { ElementsText, window } from "@/constants/sizes";
import { useToggleButton } from "@/hooks/useToggleButton";

const scale = 0.7;
const PAGE_WIDTH = window.width * scale;
const PAGE_HEIGHT = 240 * scale;

function Index() {
	const AutoPLay = useToggleButton({
		defaultValue: false,
		buttonTitle: ElementsText.AUTOPLAY,
	});

	const animationStyle: TAnimationStyle = React.useCallback((value: number) => {
		"worklet";

		const zIndex = interpolate(value, [-1, 0, 1], [10, 20, 30]);
		const rotateZ = `${interpolate(value, [-1, 0, 1], [-45, 0, 45])}deg`;
		const translateX = interpolate(
			value,
			[-1, 0, 1],
			[-window.width, 0, window.width],
		);

		return {
			transform: [{ rotateZ }, { translateX }],
			zIndex,
		};
	}, []);

	return (
		<View
			id="carousel-component"
			dataSet={{ kind: "custom-animations", name: "rotate-in-out" }}
		>
			<Carousel
				loop
				style={{
					width: window.width,
					height: 240,
					justifyContent: "center",
					alignItems: "center",
				}}
				width={PAGE_WIDTH}
				height={PAGE_HEIGHT}
				data={[...new Array(6).keys()]}
				renderItem={({ index }) => <SBItem key={index} index={index} />}
				autoPlay={AutoPLay.status}
				customAnimation={animationStyle}
			/>
		</View>
	);
}

export default Index;

```